package com.cloudy.impl;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Map;


import org.xml.sax.SAXException;

import com.cloudy.s3.response.AWSResponse;
import com.cloudy.s3.response.MetadataEntry;

import javax.xml.bind.JAXBException;

import static com.cloudy.utility.CloudyUtility.*;

public abstract class SuccessHandler{
	public <T> AWSResponse<T> handle(HttpURLConnection httpConnection) throws IOException, SAXException, JAXBException {
		AWSResponse<T> response = new AWSResponse<T>();
		Map<String, MetadataEntry> metadataEntries = getHeaders(httpConnection);
		response.setMetadataEntries(metadataEntries);
		T t = (T)getTheResponseMessage(httpConnection);

		response.setResponse(t);
		
		
		
		return response;
	}
	protected abstract <T> T getTheResponseMessage(HttpURLConnection httpConnection) throws IOException, SAXException, JAXBException;
}